package Products;

import java.util.ArrayList;
import java.util.List;

import Exceptions.CantRemoveException;
import Exceptions.ProductNeverPurchasedException;
import Exceptions.ProductSalesPriceNeverSetException;
import Magnitudes.Magnitude;
import Magnitudes.Percentage;

public class Product {

	private String name;
	private String  description;
	private String brand;
	private List<Presentation> presentations;
	private Kind kind;
	
	
	
	public Product(String name, String description, String brand,
			Kind kind, Presentation presentantion) {
		
		this.name = name;
		this.description = description;
		this.brand = brand;
		this.kind = kind;
		this.presentations = new ArrayList<Presentation>();
		this.presentations.add(presentantion);
		
	}



	public Product(String name2, String description2, String brand2,
			Kind kind, Magnitude magnitude, String codePresentation) {
		
		this.name = name2;
		this.description = description2;
		this.brand = brand2;
		this.kind = kind;
		this.presentations = new ArrayList<Presentation>();
		this.presentations.add(new Presentation(magnitude, codePresentation));		
	}



	public List<Presentation> getPresentations() {		
		return this.presentations;
	}



	public void addANewPresentation(Presentation aPresentation) {
		this.presentations.add(aPresentation);
	}



	public void addANewPresentation(Magnitude magnitude, String codePresentation) {
		this.presentations.add(new Presentation(magnitude, codePresentation));
		
	}



	public boolean isFoodstuff() {
		return this.kind.isFoodstuff();
	}



	public boolean isClothe() {
		return this.kind.isClothe();
	}



	public boolean isFootwear() {
		return (this.kind.isFootwear());
	}



	public void removePresentation(Presentation aPresentation) throws CantRemoveException {		
		if(this.presentations.contains(aPresentation) && this.presentations.size() > 1){
			this.presentations.remove(aPresentation);
		}else{
			throw new CantRemoveException();
		}					
	}



	public void updateUnitPurchasePriceBy(Percentage percentage) {
		for(Presentation presentation: presentations){
			try {
				presentation.updateUnitPurchasePriceBy(percentage);
			} catch (ProductNeverPurchasedException e) {				
				e.printStackTrace();
			}
		}
		
	}



	public void updateUnitPurchasePriceByAndUpdateSalesPrice(Percentage purchasePercentage, Percentage profitPercentage) {
		for(Presentation presentation: presentations){			
			try {
				presentation.updateUnitPurchasePriceByAndUpdateSalesPrice(purchasePercentage, profitPercentage);
			} catch (ProductNeverPurchasedException e) {				
				e.printStackTrace();
			} catch (ProductSalesPriceNeverSetException e) {				
				e.printStackTrace();
			}
		}		
	}
	
	
	
	
	
	
	
	

}
